///************************************************************************
/// <copyrigth>2018-2019 Corporation.All Rights Reserved</copyrigth>
/// <author>tangyingzhong</author>
/// <contact>tangyz114987@outlook.com</contact>
/// <version>v1.0.0</version>
/// <describe>
/// Extended exception which containing boost and stl exception
///</describe>
/// <date>2021/1/31</date>
///***********************************************************************
#ifndef BSEXCEPTION_H
#define BSEXCEPTION_H

#include <exception>
#include "boost/filesystem.hpp"
#include "boost/exception/all.hpp"

namespace SystemTool
{
	typedef boost::error_info<struct tag_err_no, int> err_no;

	typedef boost::error_info<struct tag_err_str, std::string> err_str;

	class BSException :virtual public std::exception,
		virtual public boost::exception
	{
		public:
			// Add extra info to the exception
			BSException& operator<<(int iErrorNo)
			{
				BSException& MySelf = *this;

				MySelf << err_no(iErrorNo);

				return MySelf;
			}

			// Add extra info to the exception
			BSException& operator<<(std::string strErrorStr)
			{
				BSException& MySelf = *this;

				MySelf << err_str(strErrorStr);

				return MySelf;
			}

			// Get the error no
			int ErrorNo()
			{
				return *boost::get_error_info<err_no>(*this);
			}

			// Get the error message
			std::string ErrorMsg()
			{
				std::string strStlErrorText = this->what();

				std::string strBoostErrorText = *boost::get_error_info<err_str>(*this);

				std::string strFinalErrorText = std::string("[STL ERR] ")
					+ strStlErrorText
					+" "
					+ "[BOOST ERR] "
					+ strBoostErrorText
					+ "\n";

				return strFinalErrorText;
			}
	};
}

#endif // BSEXCEPTION_H
